(function($) {

	setInterval(function() {
		var currentTime = new Date();
		var h = currentTime.getHours();
		var m = currentTime.getMinutes();
		var s = currentTime.getSeconds();

		animation($(".hand second"), s, 60);
		animation($(".hand minute"), m, 60);
		animation($(".hand hour"), h, 24);
	}, 1000);

	function animation(clock, current, total) {
		// Calculating the current angle:
		var angle = (360 / total) * (current + 1);

		var element;

		if (current == 0) {
			// Hiding the right half of the background:
			clock.rotateRight.hide();

			// Resetting the rotation of the left part:
			rotateElement(clock.rotateLeft, 0);
		}

		if (angle <= 180) {
			// The left part is rotated, and the right is currently hidden:
			element = clock.rotateLeft;
		} else {
			// The first part of the rotation has completed, so we start rotating the right part:
			clock.rotateRight.show();
			clock.rotateLeft.show();

			rotateElement(clock.rotateLeft, 180);

			element = clock.rotateRight;
			angle = angle - 180;
		}

		rotateElement(element, angle);

		// Setting the text inside of the display element, inserting a leading zero if needed:
		clock.display.html(current < 10 ? '0' + current : current);
	}

})(jQuery)